unit unRelMateriais;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QRCtrls, jpeg, QuickRpt, ExtCtrls, DB, DBTables, ZAbstractRODataset,
  ZAbstractDataset, ZDataset, StdCtrls;

type
  TfrmRelMateriais = class(TForm)
    qr: TQuickRep;
    PageHeaderBand1: TQRBand;
    QRLabel1: TQRLabel;
    QRImage1: TQRImage;
    QRLabel7: TQRLabel;
    TitleBand1: TQRBand;
    QRLabel2: TQRLabel;
    ColumnHeaderBand1: TQRBand;
    QRLabel3: TQRLabel;
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    DetailBand1: TQRBand;
    QRLabel6: TQRLabel;
    qrdbtipomaterial: TQRDBText;
    QRSubDetail1: TQRSubDetail;
    query2: TZQuery;
    qrlbdescricao: TQRLabel;
    qrlbvaloraluguel: TQRLabel;
    qrlbquantidadeatual: TQRLabel;
    qrlbtotalmateriais: TQRLabel;
    QRLabel8: TQRLabel;
    procedure DetailBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRSubDetail1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmRelMateriais: TfrmRelMateriais;

implementation

uses unRelatorios, unSenha;

{$R *.dfm}

procedure TfrmRelMateriais.DetailBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
var
  total:integer;
begin
  //ShowMessage(frmRelatorios.Query1.FieldByName('descricao').AsString +
  //'  ' + frmRelatorios.Query1.FieldByName('id_tipo_material').AsString);

   query2.sql.clear;
   query2.sql.add('select descricao, valor_unitario_aluguel, quantidade_atual from material');
   query2.sql.add('where id_tipo_material = ' + frmRelatorios.Query1.FieldByName('id_tipo_material').AsString);
   query2.Active := true;
   total:=0;
   while not query2.eof do
    begin
      total := total + query2.FieldByName('quantidade_atual').asinteger;
      query2.next;
    end;
    qrlbtotalmateriais.Caption:=inttostr(total);
    query2.first;


end;

procedure TfrmRelMateriais.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  frmRelMateriais := nil;
  action := cafree;
end;

procedure TfrmRelMateriais.QRSubDetail1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
begin
  qrlbdescricao.caption := query2.FieldByName('descricao').asstring;
  qrlbvaloraluguel.Caption := CurrToStrF(query2.FieldByName('valor_unitario_aluguel').AsFloat,ffnumber, 2);
  qrlbquantidadeatual.caption := query2.FieldByName('quantidade_atual').asstring;

end;

end.
